package com.emr.module.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.emr.module.mapper.PersonalMapper;
import com.emr.module.domain.Icd;
import com.emr.module.domain.Personal;
import com.emr.module.service.IPersonalService;
import com.emr.common.support.Convert;

/**
 * 个人病例 服务层实现
 * 
 * @author emr
 * @date 2019-02-19
 */
@Service
public class PersonalServiceImpl implements IPersonalService
{
	@Autowired
	private PersonalMapper personalMapper;

	/**
     * 查询个人病例信息
     * 
     * @param id 个人病例ID
     * @return 个人病例信息
     */
    @Override
	public Personal selectPersonalById(Integer id)
	{
	    return personalMapper.selectPersonalById(id);
	}
	
	/**
     * 查询个人病例列表
     * 
     * @param personal 个人病例信息
     * @return 个人病例集合
     */
	@Override
	public List<Personal> selectPersonalList(Personal personal)
	{
	    return personalMapper.selectPersonalList(personal);
	}
	
    /**
     * 新增个人病例
     * 
     * @param personal 个人病例信息
     * @return 结果
     */
	@Override
	public int insertPersonal(Personal personal)
	{
	    return personalMapper.insertPersonal(personal);
	}
	
	/**
     * 修改个人病例
     * 
     * @param personal 个人病例信息
     * @return 结果
     */
	@Override
	public int updatePersonal(Personal personal)
	{
	    return personalMapper.updatePersonal(personal);
	}

	/**
     * 删除个人病例对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deletePersonalByIds(String ids)
	{
		return personalMapper.deletePersonalByIds(Convert.toStrArray(ids));
	}

	//病人下拉框（此方法废除）
	@Override
	public List<Personal> selectIcdAll() {
		// TODO Auto-generated method stub
		return personalMapper.selectIcdAll();
	}

	@Override
	public List<Personal> selectUPersonalByIds(Integer id) {
		List<Personal> userPosts = personalMapper.selectUPersonalByIds(id);
        List<Personal> posts = personalMapper.selectOperationPersonal();
        for (Personal post : posts)
        {
            for (Personal userRole : userPosts)
            {
                if (post.getId().longValue() == userRole.getId().longValue())
                {
                    post.setFlag(true);
                    break;
                }
            }
        }
        return posts;
	}
	//病人下拉框
	@Override
	public List<Personal> selectOperationPersonal() {
		return personalMapper.selectOperationPersonal();
	}

}
